﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;

namespace SceneEditor
{
    public class ChangedEventArgs : EventArgs
    {
        public ChangedEventArgs(bool clearList)
        {
            this.ClearList = clearList;
        }

        public bool ClearList;
    }

    public class StackList : CollectionBase
    {
        public event ChangedEventHandler Changed;

        public EditAction Pop()
        {
            object action = this.List[0];
            this.InnerList.RemoveAt(0);

            OnChanged(new ChangedEventArgs(false));
            return (EditAction)action;
        }

        public StackList(int capacity)
            : base(capacity)
        {
            Stack<EditAction> test = new Stack<EditAction>();
        }

        protected virtual void OnChanged(ChangedEventArgs e)
        {
            if (Changed != null)
                Changed(this, e);
        }

        public delegate void ChangedEventHandler(object sender, ChangedEventArgs e);

        protected override void OnClear()
        {

            base.OnClear();
        }

        public void Push(EditAction action, bool clearList)
        {
            if (this.Count + 1 > Capacity)
                this.InnerList.RemoveAt(this.Count - 1);

            this.List.Insert(0, action);

            OnChanged(new ChangedEventArgs(clearList));
        }

        public new void Clear()
        {
            this.InnerList.Clear();
            OnChanged(new ChangedEventArgs(false));
        }
    }
}
